package com.example.springprinciple.config;

import com.example.springprinciple.model.Dog;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Scope;
import org.springframework.web.context.annotation.ApplicationScope;
import org.springframework.web.context.annotation.RequestScope;
import org.springframework.web.context.annotation.SessionScope;

@Configuration
public class DogBeanConfig {
    //使用@Bean将对象交给spring进行管理
    @Bean
    public Dog dog(){
        Dog dog = new Dog();
        dog.setName("wangcai");
        return dog;
    }

    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
    public Dog singletonDog(){
        Dog dog =new Dog();
        return dog;
    }

    //原型作用域
    @Bean
    @Scope(ConfigurableBeanFactory.SCOPE_PROTOTYPE)
    public Dog prototypeDog(){
        Dog dog =new Dog();
        return dog;
    }
    //请求作用域
    @Bean
    @RequestScope
    public Dog requestDog(){
        Dog dog =new Dog();
        return dog;
    }

    //会话作用域
    @Bean
    @SessionScope
    public Dog sessionDog(){
        Dog dog =new Dog();
        return dog;
    }

    @Bean
    @ApplicationScope
    public Dog applicationDog(){
        Dog dog =new Dog();
        return dog;
    }
}
